/*
* PROJECT: Happy New Year
* VERSION: 1.0
* AUTHOR: Mattias Thell
* URL: http://www.mattiasthell.com
*
* */

#include "Text.hpp"
#include "Settings.hpp"
#include "World.hpp"

namespace hny {

	Text::Text(World* world, const std::string& str, const hgeVector& pos, const hgeColor& col, float life, float scale) 
		:Actor(world, Kind_Text), 
		mString(str), mColor(col), mLife(life), mScale(scale), mAge(0.0f)
	{
		Actor::SetPosition(pos);
		mFont = Settings::GetInstance()->ComboFont;
		mColor.a = 0.0f;
	}

	Text::~Text() {}

	void Text::Update(float dt)
	{
		mAge += dt;
		mScale += dt*0.1f;

		if(!IsDying()) {
			float d = 0.2f;

			if(mColor.a < 1.0f)
				mColor.a += dt*0.4f;
			

			if(mAge >= mLife)
				SetIsDying();
		}
		else {
			mColor.a -= dt * 5.0f;
			if(mColor.a <= 0.0)
				Kill();
		}
	}

	void Text::Draw()
	{
		mFont->SetScale(mScale);
		mFont->SetColor(mColor.GetHWColor());
		hgeVector pos = Actor::GetPosition();
		mFont->Render(pos.x, pos.y, HGETEXT_MIDDLE, mString.c_str());
	}
}